package com.library.weidget;

import android.app.Dialog;
import android.content.Context;
import android.graphics.drawable.AnimationDrawable;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.jtjrenren.android.taxi.passenger.R;
import com.library.utils.StringUtils;

/**
 * Created by Administrator on 2016/1/26.
 */
public class CustomeWaittingDialog extends Dialog {
    private ImageView iv_loadding;
    private TextView tv_desc;
    private AnimationDrawable anim;

    private String desc = "数据加载中";

    public CustomeWaittingDialog(Context context, int theme) {
        super(context, theme);
        initView();
    }


    public CustomeWaittingDialog(Context context, String desc) {
        super(context, R.style.dlg_common);
        if (!StringUtils.isEmpty(desc))
            this.desc = desc;
        initView();
    }

    private void initView() {
        View view = View.inflate(getContext(),
                R.layout.dlg_custome_waitting, null);
        tv_desc = (TextView) view
                .findViewById(R.id.custome_waitting_dialog_tv_desc);
        tv_desc.setText(desc);

        iv_loadding = (ImageView) view
                .findViewById(R.id.custome_waitting_dialog_iv);

        setContentView(view);
    }


    public void setDesc(String desc) {
        if (!StringUtils.isEmpty(desc))
            tv_desc.setText(desc);
    }

    @Override
    public void show() {
        super.show();
        anim = (AnimationDrawable) iv_loadding.getBackground();
        anim.start();
    }

    @Override
    public void dismiss() {
        super.dismiss();
        anim = (AnimationDrawable) iv_loadding.getBackground();
        anim.stop();
    }
}
